-
Notifications
You must be signed in to change notification settings - Fork 1
endpoint for status of the user #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
api/groups/common_test.go
Outdated
| {Name: "/sign-multiple-transactions", Open: true}, | ||
| {Name: "/set-security-mode", Open: true}, | ||
| {Name: "/unset-security-mode", Open: true}, | ||
| {Name: "/security-status", Open: true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this can be extended in the future, perhaps we rename it to something more generic like user-status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed it
api/groups/guardianGroup.go
Outdated
| logUserStatusRequest(userIp, userAgent, &request, debugErr) | ||
| }() | ||
|
|
||
| err := json.NewDecoder(c.Request.Body).Decode(&request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think request body and UserStatusRequest is needed here.. perhaps it can be something similar to node's /address/:address endpoint instead (/guardian/user-status/erd1....)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| { Name = "/sign-multiple-transactions", Open = true, Auth = false, MaxContentLength = 1500000 }, | ||
| { Name = "/set-security-mode", Open = true, Auth = false, MaxContentLength = 200 }, | ||
| { Name = "/unset-security-mode", Open = true, Auth = false, MaxContentLength = 200 }, | ||
| { Name = "/security-status", Open = true, Auth = false, MaxContentLength = 200 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaxContentLength not needed, it does not apply for get requests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
core/constants.go
Outdated
| // NoExpiryValue is the returned value for a persistent key expiry time | ||
| const NoExpiryValue = -1 | ||
|
|
||
| type Status int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comments on new fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
core/requests/types.go
Outdated
| UserAddr string `json:"user"` | ||
| } | ||
|
|
||
| // UserStatusResponse - is the JSON response for the user status interrogation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // UserStatusResponse - is the JSON response for the user status interrogation | |
| // UserStatusResponse is the JSON response for the user status request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
resolver/serviceResolver.go
Outdated
| return resolver.verifyCodesReturningGuardian(userAddress, txs[0].GuardianAddr, userIp, code, secondCode) | ||
| } | ||
|
|
||
| func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) { | |
| func (resolver *serviceResolver) getUserStatus(userAddr string) (core.Status, error) { |
no verification done here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed it
resolver/serviceResolver.go
Outdated
| func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) { | ||
| userAddress, err := sdkData.NewAddressFromBech32String(userAddr) | ||
| if err != nil { | ||
| return 0, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return 0, err | |
| return core.NotSet, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed now
resolver/serviceResolver.go
Outdated
| addressBytes := userAddress.AddressBytes() | ||
| resolver.userCritSection.RLock(string(addressBytes)) | ||
| _, err = resolver.getUserInfo(addressBytes) | ||
| resolver.userCritSection.RUnlock(string(addressBytes)) | ||
| if err != nil { | ||
| return -1, err | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be removed 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it now
testscommon/rateLimiterStub.go
Outdated
| if r.GetSecurityStatusCalled != nil { | ||
| return r.GetSecurityStatusCalled(key) | ||
| } | ||
| return -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return -1 | |
| return core.NotSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
testscommon/rateLimiterMock.go
Outdated
|
|
||
| // GetSecurityStatus - | ||
| func (r *RateLimiterMock) GetSecurityStatus(key string) core.Status { | ||
| return 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return 0 | |
| return core.NotSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
api/groups/guardianGroup.go
Outdated
| signMultipleTransactionsPath = "/sign-multiple-transactions" | ||
| setSecurityModeNoExpirePath = "/set-security-mode" | ||
| unsetSecurityModeNoExpirePath = "/unset-security-mode" | ||
| getSecurityStatus = "/security-status" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to getSecurityStatusPath?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
core/constants.go
Outdated
| type Status int | ||
|
|
||
| const ( | ||
| NotSet Status = iota | ||
| ManualSet | ||
| AutomaticallySet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add missing comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these changes needed? did you run go mod tidy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
| return totp.rateLimiter.UnsetSecurityModeNoExpire(key) | ||
| } | ||
|
|
||
| // GetSecurityStatus - returns the status of the security mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // GetSecurityStatus - returns the status of the security mode | |
| // GetSecurityStatus returns the status of the security mode |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
resolver/serviceResolver.go
Outdated
| _, err = resolver.getUserInfo(addressBytes) | ||
| resolver.userCritSection.RUnlock(string(addressBytes)) | ||
| if err != nil { | ||
| return -1, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what -1 means here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set it as a error value, not needed it anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this -1 still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, all those lines are removed now.
|
|
||
| // swagger:route GET /security-status Guardian getSecurityStatus | ||
| // Returns the security status. | ||
| // swagger:route GET /user-status Guardian getSecurityStatus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // swagger:route GET /user-status Guardian getSecurityStatus | |
| // swagger:route GET /user-status Guardian getUserStatus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| // swagger:route GET /security-status Guardian getSecurityStatus | ||
| // Returns the security status. | ||
| // swagger:route GET /user-status Guardian getSecurityStatus | ||
| // Returns the security status of the user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Returns the security status of the user. | |
| // Returns the status of the user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
api/groups/guardianGroup_test.go
Outdated
|
|
||
| facade := mockFacade.GuardianFacadeStub{ | ||
| GetSecurityStatusCalled: func(request requests.UserStatusRequest) (*requests.UserStatusResponse, error) { | ||
| GetSecurityStatusCalled: func(userAddress string) (*requests.UserStatusResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename this as well to GetUserStatusCalled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
redis/redisLimiter.go
Outdated
| if trials < maxFailures && expTime != core.NoExpiryValue { | ||
| trials, err := strconv.ParseInt(dbVal, 10, 64) | ||
| if err != nil { | ||
| log.Debug("error when returning security status", "err", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| log.Debug("error when returning security status", "err", err) | |
| log.Debug("error when converting security status", "err", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
resolver/serviceResolver.go
Outdated
| // GetSecurityStatus gets the user's security status | ||
| func (resolver *serviceResolver) GetSecurityStatus(request requests.UserStatusRequest) (*requests.UserStatusResponse, error) { | ||
| status, err := resolver.verifyUserReturningSecurityStatus(request.UserAddr) | ||
| // GetUserStatus gets the user's security status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // GetUserStatus gets the user's security status | |
| // GetUserStatus gets the user's status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
testscommon/serviceResolverStub.go
Outdated
| SetSecurityModeNoExpireCalled func(userIp string, request requests.SecurityModeNoExpire) (*requests.OTPCodeVerifyData, error) | ||
| UnsetSecurityModeNoExpireCalled func(userIp string, request requests.SecurityModeNoExpire) (*requests.OTPCodeVerifyData, error) | ||
| GetSecurityStatusCalled func(request requests.UserStatusRequest) (*requests.UserStatusResponse, error) | ||
| GetSecurityStatusCalled func(userAddress string) (*requests.UserStatusResponse, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| GetSecurityStatusCalled func(userAddress string) (*requests.UserStatusResponse, error) | |
| GetUserStatusCalled func(userAddress string) (*requests.UserStatusResponse, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we need to also generate swagger files based on these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these empty lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observations after testing:
- swagger not working, could not add parameters on the request
| } | ||
| }, | ||
| "userStatusResponse": { | ||
| "description": "The status of the operation", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
status of which operation?
this should be the address/user status on the TCS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
core/constants.go
Outdated
| const NoExpiryValue = -1 | ||
|
|
||
| // Status represents the status of the security mode | ||
| type Status int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is too generic, especially when used for the security mode
maybe EnhancedSecurityModeStatus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
core/requests/types.go
Outdated
|
|
||
| // UserStatusResponse is the JSON response for the user status interrogation | ||
| type UserStatusResponse struct { | ||
| SecurityStatus int `json:"status"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename to SecurityModeStatus? or EnhancedSecurityModeStatus?
SecurityStatus = NotSet doesn't sound good, as the account has protection via regular 2FA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
resolver/serviceResolver.go
Outdated
| _, err = resolver.getUserInfo(addressBytes) | ||
| resolver.userCritSection.RUnlock(string(addressBytes)) | ||
| if err != nil { | ||
| return -1, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this -1 still needed?
The base branch was changed.
No description provided.